package test;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import javax.imageio.ImageIO;

abstract class FlashInter{
	private double currentFps = 0;
	private static int maxFps = 0;
	 double fps=0.30;
	int x;
	int y;
	public FlashInter(int x, int y) {
		currentFps = 0;
		this.x = x;
		this.y = y;
	}
}
class Flash {
	// private Vector< Image > images;
	static BufferedImage[] images;
	static int num=8;
	protected static int width;
	protected static int height;
	
	private double currentFps = 0;
	private static int maxFps = 0;
	 double fps=0.30;
	int x;
	int y;
	static {
		if (images == null) {
			maxFps = num - 1;
			images = new BufferedImage[num];
			for (int i = 0; i < num; i++) {
				try {

					String str = null;
					if (i < 10) {
						str = FlashBoom.class
								.getClassLoader()
								.getResource(
										"fla/" + "blast" + (i + 1) + ".gif")
								.getPath();
					} else {
						str = FlashBoom.class.getClassLoader()
								.getResource("fla/" + "0" + i + ".gif")
								.getPath();
					}
					File file = new File(str);
					if (file.exists() && file.isFile()) {
						images[i] = ImageIO.read(new FileInputStream(file));

						if (images[i] != null) {
							System.out.println("Loading " + str + "..OK!");
							if (i == 0) {
								width = images[i].getWidth() / 2;
								height = images[i].getHeight() / 2;
							}
							System.out.println(str + "");
						} else {
							System.out.println("Loading " + str + "..faill!");
						}
					}
				} catch (IOException ioe) {
					System.out.println("");
					ioe.printStackTrace();
				}
			}
		}
	}

	public Flash(int x, int y) {

		currentFps = 0;
		this.x = x;
		this.y = y;
	}

	public void paint(Graphics g) {
		if (currentFps >= maxFps) {
			fps = 0;
			currentFps = -1;
		}
		if (currentFps != -1) {
			g.drawImage(images[(int) (currentFps += fps)], x - width / 2, y,
					width, height, null);
		}

	}

	public Image getImg() {

		return images[(int) (currentFps += fps)];
	}
}